package src.rmi;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.util.Set;
import src.domain.MailBox;
import src.domain.OutgoingMessage;
import src.domain.PostOffice;
import src.domain.User;



public class ImplementationClientService {
	
	private Service service;

	public ImplementationClientService(){
		this.initService();
	}
	
	public void initService() {
		try {
			this.service = (Service) Naming
					.lookup("//localhost/ServidorServicio");
		} catch (Exception e) {
			e.printStackTrace();
			//System.exit(1);
		}	
	}
	
	public void saveUser(String name, String userName, String country,
			String city, String address, String phoneNumber, boolean active)
			throws RemoteException {
		this.service.saveUser(name, userName, country, city, address, phoneNumber, active);
		
	}

	
	public void updateUser(User user) throws RemoteException {
		this.service.updateUser(user);
		
	}

	
	public void deleteUser(long idUser) throws RemoteException {
		this.service.deleteUser(idUser);
		
	}

	
	public Set<User> getAllUsers() throws RemoteException {
		return this.service.getAllUsers();
	}
	
	public Set<User> getUsers(String name) throws RemoteException {
		return this.service.getUsers(name);
	}

	
	public void savePostOffice(String name, Set<MailBox> mailBoxes, Set<PostOffice> trustOffices) throws RemoteException {
		this.service.savePostOffice(name, mailBoxes, trustOffices);
		
	}

	
	public void updatePostOffice(PostOffice postOffice) throws RemoteException {
		this.service.updatePostOffice(postOffice);	
	}

	public void deletePostOffice(long idPostOffice) throws RemoteException {
		this.service.deletePostOffice(idPostOffice);	
	}
	
	public Set<PostOffice> getAllPostOffices() throws RemoteException {
		return this.service.getAllPostOffices();
	}
	
	public Set<PostOffice> getPostOffices(String name) throws RemoteException {
		return this.service.getPostOffices(name);
	}
	
	public Set<PostOffice> getAvailablePostOffices(final PostOffice postOffice)throws RemoteException {
		return this.service.getAvailablePostOffices(postOffice);
	}
	
	public  void saveMailBox(String name, String pass, boolean active,User user,Set<PostOffice> postOffices) throws RemoteException{	
		this.service.saveMailBox(name, pass, active,user,postOffices);		
	}
	
	public void updateMailBox(MailBox mailBox) throws RemoteException{
		this.service.updateMailBox(mailBox);
	}
	
	
	public void deleteMailBox(long idMailBox) throws RemoteException{
		this.service.deleteMailBox(idMailBox);
	}
	
	
	public Set<MailBox> getAllMailBoxes() throws RemoteException{
		return this.service.getAllMailBoxes();
	}
	
	public Set<MailBox> getMailBoxes(String nameMailBox) throws RemoteException{
		return this.service.getMailBoxes(nameMailBox);
	}
	
	public Set<PostOffice> getUnassignedPostOffices(Long idMailBox) throws RemoteException{
		return this.service.getUnassignedPostOffices(idMailBox);
	}
	
	public MailBox getMailBoxByName(String nameMailBox)throws RemoteException{
		return this.service.getMailBoxByName(nameMailBox);
	}
	
	public User getUserByUserName(String userName)throws RemoteException{
		return this.service.getUserByUserName(userName);
	}
	
	public PostOffice getPostOfficeByName(String postOfficeName)throws RemoteException{
		return this.service.getPostOfficeByName(postOfficeName);
	}
	
	public Set<MailBox> getMailBoxesByPostOffice(long idPostOffice)throws RemoteException{
		return this.service.getMailBoxesByPostOffice(idPostOffice);
	}
	
	public Set<OutgoingMessage> getOutgoingMessagesByMailBox(long idMailBox)throws RemoteException{
		return this.service.getOutgoingMessagesByMailBox(idMailBox);
	}
	
	public Set<MailBox> getMailBoxesByUser(long idUser)throws RemoteException{
		return this.service.getMailBoxesByUser(idUser);
	}
}
